home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 1.9 KB | 80 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // Restricted Rights Legend
- // Use, duplication, or disclosure is subject to restrictions as set forth
- // in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer
- // Software clause at DFARS 252.227-7013.
- //
- // BCSearcT.cpp
- //
- // This file contains the definitions for the tree searching tools.
-
- #include "BCSearcT.h"
-
- template<class Tree>
- BC_TBinaryTreeSearch<Tree>::BC_TBinaryTreeSearch() {}
-
- template<class Tree>
- BC_TBinaryTreeSearch<Tree>::~BC_TBinaryTreeSearch() {}
-
- template<class Tree>
- BC_Boolean BC_TBinaryTreeSearch<Tree>::
- PreOrder(const Tree& target, BC_Boolean (*process)(const Tree&))
- {
- Tree subtree;
- if (!target.IsNull()) {
- if (!process(target))
- return 0;
- subtree = target;
- subtree.LeftChild();
- if (!PreOrder(subtree, process))
- return 0;
- subtree = target;
- subtree.RightChild();
- if (!PreOrder(subtree, process))
- return 0;
- }
- return 1;
- }
-
- template<class Tree>
- BC_Boolean BC_TBinaryTreeSearch<Tree>::
- InOrder(const Tree& target, BC_Boolean (*process)(const Tree&))
- {
- Tree subtree;
- if (!target.IsNull()) {
- subtree = target;
- subtree.LeftChild();
- if (!InOrder(subtree, process))
- return 0;
- if (!process(target))
- return 0;
- subtree = target;
- subtree.RightChild();
- if (!InOrder(subtree, process))
- return 0;
- }
- return 1;
- }
-
- template<class Tree>
- BC_Boolean BC_TBinaryTreeSearch<Tree>::
- PostOrder(const Tree& target, BC_Boolean (*process)(const Tree&))
- {
- Tree subtree;
- if (!target.IsNull()) {
- subtree = target;
- subtree.LeftChild();
- if (!PostOrder(subtree, process))
- return 0;
- subtree = target;
- subtree.RightChild();
- if (!PostOrder(subtree, process))
- return 0;
- if (!process(target))
- return 0;
- }
- return 1;
- }
-